package Modellus.WinUI.ExampleTable;

import javax.swing.*;
import javax.swing.table.TableCellRenderer;
import java.awt.*;

class TransparentHeaderRenderer extends JLabel implements TableCellRenderer {
    public TransparentHeaderRenderer() {
        Font font = new Font("Verdana", Font.PLAIN, 10);
        setFont(font.deriveFont(Font.BOLD));
        setHorizontalAlignment(SwingConstants.CENTER);
        setBorder(BorderFactory.createLineBorder(Color.gray));
    }

    @Override
    public void paintComponent(Graphics g) {
        Graphics2D g2d = (Graphics2D) g.create();

        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                RenderingHints.VALUE_ANTIALIAS_ON);
        g2d.setColor(new Color(0, 0, 255, 50));
        g2d.fillRect(0, 0, getSize().width, getSize().height);
        super.paintComponent(g2d);
    }

    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
        if (value != null) {
            setText(value.toString());
        } else {
            setText("");
        }
        return this;
    }
}